import type { PaginationProps } from "./types/pagination";
import type {
	BasicColumn,
	FetchSetting,
	// SizeType,
	SorterResult,
	TableCustomRecord,
	TableRowSelection,
	TableSetting
} from "./types/table";
import type { FormProps } from "@/components/Form";
import { DEFAULT_FILTER_FN, DEFAULT_SIZE, DEFAULT_SORT_FN, FETCH_SETTING } from "./const";
import { ActionItem } from "./types/tableAction";

export interface BasicPropsType {
	clickToRowSelect?: boolean;
	isTreeTable?: boolean;
	tableSetting?: TableSetting;
	inset?: boolean;
	sortFn?: (sortInfo: SorterResult) => any;
	filterFn?: (data: Partial<Recordable<string[]>>) => any;
	showTableSetting?: boolean;
	autoCreateKey?: boolean;
	striped?: boolean;
	showSummary?: boolean;
	summaryFunc?: (...arg: any[]) => any[];
	summaryData?: Recordable[];
	indentSize?: number; // 24
	canColDrag?: boolean;
	api?: (...arg: any[]) => Promise<any>;
	beforeFetch?: Fn;
	afterFetch?: Fn;
	handleSearchInfoFn?: Fn;
	fetchSetting?: FetchSetting;
	// 立即请求接口
	immediate?: boolean;
	emptyDataIsShowTable?: boolean;
	// 额外的请求参数
	searchInfo?: Recordable;
	// 默认的排序参数
	defSort?: Recordable;
	// 使用搜索表单
	useSearchForm?: boolean;
	// 表单配置
	formConfig?: Partial<FormProps>;
	columns?: BasicColumn[];
	showIndexColumn?: boolean;
	indexColumnProps?: BasicColumn;
	actionColumn?: BasicColumn;
	ellipsis?: boolean;
	isCanResizeParent?: boolean;
	canResize?: boolean;
	clearSelectOnPageChange?: boolean;
	resizeHeightOffset?: number;
	rowSelection?: TableRowSelection | null;
	title?: string | ((data: Recordable) => string);
	titleHelpMessage?: string | string[];
	maxHeight?: number;
	dataSource?: Recordable[];
	rowKey?: string | ((record: Recordable) => string);
	bordered?: boolean;
	pagination?: PaginationProps | boolean;
	loading?: boolean;
	rowClassName?: (record: TableCustomRecord<any>, index: number) => string;
	scroll?: { x: number | string | true; y: number | string };
	beforeEditSubmit?: (data: { record: Recordable; index: number; key: string | number; value: any }) => Promise<any>;
	size?: string;
}

export const BasicPropsDefault = {
	clickToRowSelect: true,
	sortFn: DEFAULT_SORT_FN,
	filterFn: DEFAULT_FILTER_FN,
	autoCreateKey: true,
	striped: true,
	indentSize: 24,
	canColDrag: true,
	fetchSetting: FETCH_SETTING,
	immediate: true,
	emptyDataIsShowTable: true,
	showIndexColumn: true,
	ellipsis: true,
	// 继承高度可以实现宽高属性穿透
	isCanResizeParent: false,
	canResize: true,
	resizeHeightOffset: 0,
	size: DEFAULT_SIZE,
	// 固定滚动区域
	maxHeight: 300,
	// 显示表格设置
	showTableSetting: true
};

export interface ActionPropsType {
	actions?: ActionItem[];
	dropDownActions?: ActionItem[];
	divider?: boolean;
	outside?: boolean;
	stopButtonPropagation?: boolean;
}

export const ActionPropsDefault = {
	divider: true,
	stopButtonPropagation: false
};

export interface HeaderPropsType {
	title: string | ((data: any) => string);
	tableSetting: TableSetting;
	showTableSetting: boolean;
	titleHelpMessage: string | string[];
}

export const HeaderPropsDefault = {
	titleHelpMessage: ""
};
